package com.shuoyue.ycgk.ui.questionbank.practice.freedom;

import com.shuoyue.ycgk.base.BaseModel;
import com.shuoyue.ycgk.base.BasePresenter;
import com.shuoyue.ycgk.base.BaseResult;
import com.shuoyue.ycgk.base.BaseView;
import com.shuoyue.ycgk.entity.FreedomGroup;
import com.shuoyue.ycgk.entity.QuestionParent;
import com.shuoyue.ycgk.entity.UserAnswerPager;
import com.shuoyue.ycgk.net.RetrofitClient;
import com.shuoyue.ycgk.net.base.ApiSubscriber;
import com.shuoyue.ycgk.net.gsondefaultadapter.Optional;

import java.util.List;

import io.reactivex.Observable;

public interface FreedomContract {
    interface View extends BaseView {

        void getFreedomSuc(List<QuestionParent> freedomGroups);

        void getQuestionsSuc(List<FreedomGroup> list);

    }

    class Presenter extends BasePresenter<View> {
        Model model = new Model();



        public void getFreedomQuestion(int modelId) {
            apply(model.getFreedomQuestion(modelId))
                    .subscribe(new ApiSubscriber<Optional<List<FreedomGroup>>>(mView, this) {
                        @Override
                        public void onNext(Optional<List<FreedomGroup>> optional) {
                            super.onNext(optional);
                            mView.getQuestionsSuc(optional.getIncludeNull());
                        }

                    });
        }

    }

    class Model extends BaseModel {
        Observable<BaseResult<List<FreedomGroup>>> getFreedomQuestion(int paperId) {
            return RetrofitClient.getInstance().getApi().getFreedomQuestion(paperId);
        }
    }
}
